import 'dart:convert';

import 'package:file_picker/file_picker.dart';
import 'package:flutter_application_pd/common/index.dart';
import 'package:flutter_application_pd/common/models/token_list.dart';
import 'package:get/get.dart';

class HomeController extends GetxController {
  HomeController();
  TokenList tokenList = TokenList(code: 0, data: null, msg: "");

  _initData() {
    update(["home"]);
  }

  void uploadFile() async {
    FilePickerResult? result = await FilePicker.platform.pickFiles();

    if (result != null) {
      // print('object$result.files.single.path');
      var response = await Api.instance
          .uploadFile('/index/daorutoken', result.files.single.path.toString());
      var res = jsonDecode(response.data);
      tokenList = TokenList.fromJson(res);
      // var k = tokenList.data!.drchenggong!.length;
      // print('objectxxxxxxxxxxxxxxxxxxx$k');
    } else {
      // User canceled the picker
    }
  }

  void onTap() {}

  // @override
  // void onInit() {
  //   super.onInit();
  // }

  @override
  void onReady() {
    super.onReady();
    _initData();
  }

  // @override
  // void onClose() {
  //   super.onClose();
  // }
}
